/**
 * Created by Administrator on 2018/9/29.
 */
var dataInit1;
var dataInit2;
var dataInit3;

function financialDataMet($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    //初始化出差报销
    $scope.financialQuery = {};

    //初始化当前
    var picker2 = $('#financialtime1').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $scope.financialQuery.startTime = result;
            //console.log(result);
        }
    })
    var picker3 = $('#financialtime2').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $scope.financialQuery.endTime = result;
            //console.log(result);
        }
    })
    $scope.financialReportChange = function (a) {

        $scope.financialQuery = {};
        $scope.financialQuery.financialReportParam = a;
        $("#financialtime1").val("");
        $("#financialtime2").val("");
        if (a == 'cashType' || a == "entertainDinner") {
            if (!angular.isUndefined(dataInit1)) {
                dataInit1.parameters = {
                    "financialReportParam": a,
                    "complete": "completed"
                };
                dataInit1.refresh(true);
            } else {
                dataInit1 = CertusJsonAjax.dataInit("financialReportQuery", {
                    "financialReportParam": a,
                    "complete": "completed"
                }, financialReport, 'other2ContainerFinancia0', 'otherTool2ContainerFinancia0');
            }

            $(".lalala2").hide();
            $(".lalala1").show();
            $(".lalala3").hide();
        } else if (a == 'trmType') {
            if (!angular.isUndefined(dataInit2)) {
                dataInit2.parameters = {
                    "financialReportParam": a,
                    "complete": "completed"
                };
                dataInit2.refresh(true);
            } else {
                dataInit2 = CertusJsonAjax.dataInit("financialReportQuery", {
                    "financialReportParam": a,
                    "complete": "completed"
                }, financialReport1, 'other2ContainerFinancial1', 'otherTool2ContainerFinancial1');
            }
            $(".lalala2").show();
            $(".lalala1").hide();
            $(".lalala3").hide();
        } else if (a == "receptionType") {
            if (!angular.isUndefined(dataInit3)) {
                dataInit3.parameters = {
                    "financialReportParam": a,
                    "complete": "completed"
                };
                dataInit3.refresh(true);
            } else {
                dataInit3 = CertusJsonAjax.dataInit("financialReportQuery", {
                    "financialReportParam": a,
                    "complete": "completed"
                }, financialReport1, 'other2ContainerFinancial2', 'otherTool2ContainerFinancial2');
            }
            $(".lalala3").show();
            $(".lalala1").hide();
            $(".lalala2").hide();

        }
        $scope.financialQuery.complete = "completed";
    }

    $scope.financialComplete = function (b) {
        $scope.financialQuery.financialReportParam = $scope.financialReportSe
        if (dataInit1) {

            dataInit1.pager.nowPage = 1
            dataInit1.parameters = $scope.financialQuery;
            dataInit1.refresh(true);
        }
        if (dataInit2) {

            dataInit2.pager.nowPage = 1
            dataInit2.parameters = $scope.financialQuery;
            dataInit2.refresh(true);
        }
        if (dataInit3) {
            dataInit3.pager.nowPage = 1
            dataInit3.parameters = $scope.financialQuery;
            dataInit3.refresh(true);
        }
    }

    $scope.completedSelect = [{
            name: "完成",
            code: "completed"
        },
        {
            name: "未完成",
            code: "uncompleted"
        }
    ]
    $scope.financialQuery.complete = "completed";
    $scope.financialReportSelect = [{
            name: "出差报销",
            code: "trmType"
        },
        {
            name: "现金报销",
            code: "cashType"
        }, {
            name: "招待报销",
            code: "receptionType"
        }
    ]
    $scope.financialReportSe = "cashType";
    if (!angular.isUndefined(dataInit2)) {
        dataInit2.parameters = {
            financialReportParam: "cashType",
            "complete": "completed"
        };
        dataInit2.refresh(true);
    } else {
        dataInit2 = CertusJsonAjax.dataInit("financialReportQuery", {
            "financialReportParam": 'cashType',
            "complete": "completed"
        }, financialReport, 'other2ContainerFinancial1', 'otherTool2ContainerFinancial1');
    }
    $scope.financialSearch = function () {
        $scope.financialQuery.financialReportParam = $scope.financialReportSe

        if (dataInit1) {
            dataInit1.pager.nowPage = 1
            dataInit1.parameters = $scope.financialQuery;
            dataInit1.refresh(true);
        }
        if (dataInit2) {
            dataInit2.pager.nowPage = 1
            dataInit2.parameters = $scope.financialQuery;
            dataInit2.refresh(true);
        }
        if (dataInit3) {
            dataInit3.pager.nowPage = 1
            dataInit3.parameters = $scope.financialQuery;
            dataInit3.refresh(true);
        }
    }
}

//现金报销 columns
var financialReport = [{
    id: 'financeCode',
    title: '财务单号',
    type: 'string',
    width: 220,
    columnClass: 'text-center',
}, {
    id: 'applyTime',
    title: '报销申请日期',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.applyTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
        return content;
    }
}, {
    id: 'paymentTime',
    title: '付款确认日期',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.paymentTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
        return content;
    }
}, {
    id: 'applyUserName',
    title: '申请人',
    type: 'string',
    width: 75,
    columnClass: 'text-center'
}, {
    id: 'projNames',
    title: '相关项目',
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'financialTotalMoney',
    title: '报销单总金额',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'indoorTraffic',
    title: '市内交通',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'officeExpenses',
    title: '办公费用',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'entertainDinner',
    title: '招待应酬',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'consumable',
    title: '低值易耗品',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'lunchAmount',
    title: '餐费',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'communicationFee',
    title: '通讯费',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'carFee',
    title: '车辆',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'elseFee',
    title: '其他费用',
    type: 'string',
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}];

//出差 报销 columns
var financialReport1 = [{
    id: 'rtCode',
    title: '财务单号',
    type: 'string',
    width: 220,
    columnClass: 'text-center',
}, {
    id: 'createTime',
    title: '报销申请日期',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.createTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
        return content;
    }
}, {
    id: 'updateTime',
    title: '付款确认日期',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.updateTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
        return content;
    }
}, {
    id: 'applyManName',
    title: '申请人',
    type: 'string',
    width: 75,
    columnClass: 'text-center'
}, {
    id: 'projName',
    title: '相关项目',
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'receptionStandard',
    title: '报销单总金额',
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'receptionStandard',
    title: '招待费',
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}];